﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;

namespace EstateappraisalApi.Controllers
{
    /// <summary>
    /// 部门表
    /// </summary>
    public class DepartmentController : ApiController
    {
        // GET api/department

        DepartmentBLL bll = new DepartmentBLL();

        /// <summary>
        /// 显示所有部门信息
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Department> Get()
        {
            return bll.ShowDepartment();
        }

        // GET api/department/5
        /// <summary>
        /// 查询单个部门信息
        /// </summary>
        /// <param name="department_Id"></param>
        /// <returns></returns>
        public Department Get(int department_Id)
        {
            return bll.BackDepartment(department_Id);
        }

        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="value"></param>
        public int Post([FromBody]Department mod)
        {
            mod.department_CreatePeople = "1";
            mod.department_CreateTime = DateTime.Now;
            if (bll.AddDepartment(mod))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        // PUT api/department/5
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        public int Put([FromBody]Department m)
        {
            m.department_CreatePeople = "1";
            m.department_CreateTime = DateTime.Now;
            if (bll.UpdDepartment(m, m.department_Id))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }

        
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public int Delete(int id)
        {
            Department m = new Department();
            m.department_Id = id;
            if (bll.DelDepartment(m))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }
}
